package com.foreknow.demo11;

import java.util.*;

public class StudentDemo {
    public static void main(String[] args) {
        Student s1 = new Student();
        Student s2 = new Student();
        Student s3 = new Student();
        s1.setId("1001");
        s1.setName("aaa");
        s2.setId("1002");
        s2.setName("bbb");
        s3.setId("1003");
        s3.setName("ccc");

        Map<String,Student> m1 = new HashMap<>();
        Map<String,Student> m2 = new HashMap<>();
        Map<String,Student> m3 = new HashMap<>();
        m1.put("1",s1);
        m2.put("2",s2);
        m3.put("3",s3);

        List<Map<String,Student>> list = new ArrayList<>();
        list.add(m1);
        list.add(m2);
        list.add(m3);
        //从集合中获取元素
        System.out.println("--------------");
        for (int i = 0;i<list.size();i++){
            Map<String,Student> map =list.get(i);
            //对Map集合进行遍历
            Set<Map.Entry<String,Student>> it = map.entrySet();
            Iterator<Map.Entry<String,Student>> iterator = it.iterator();
            while (iterator.hasNext()) {
                Map.Entry<String, Student> entry = iterator.next();
                String k = entry.getKey();
                Student v = entry.getValue();
                System.out.println(k + " | " +v.getId()+ " | " +  v.getName());
                System.out.println("--------------");
            }
        }
    }
}
